<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="xbsj-labels" content="Earth示例">
    </meta>
    <title>影像-zIndex</title>
    <!-- 0 引入js文件：XbsjEarth.js和vue.min.js -->
    <script src="../../XbsjEarth/XbsjEarth.js"></script>
    <script src="./scripts/vue.min.js"></script>
    <style>
        html,
        body {
            width: 100%;
            height: 100%;
            margin: 0px;
            padding: 0px;
        }

        .box span{
            display: inline-block;
            margin-top: 10px;
        }

        .defultbtn {
            display: inline-block;
            text-align: center;
            min-width: 60px;
            height: 38px;
            padding: 0 10px;
            line-height: 38px;
            border-radius: 100px;
            border: 1px solid #C9C9C9;
            background-color: #FFF;
            color: #555;
            cursor: pointer;
            margin-left: 20px;
            margin-bottom: 10px;
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
        }

        .defultbtn:hover {
            background-color: #b3daf8;
        }

        .tip {
            margin-bottom: 10px;
            color: #ff7171;
        }
    </style>
</head>

<body>
    <div id="vueApp" style="width: 100%; height: 100%; background: grey; position: relative;">
        <earth-comp></earth-comp>
    </div>

    <script>
        // 1 创建Earth的vue组件
        var EarthComp = {
            template: `
                <div style="width: 100%; height: 100%">
                    <div ref="earthContainer" style="width: 100%; height: 100%">
                    </div>
                    <div class="box" style="position: absolute; left: 18px; top: 18px; color: white; background: rgba(0, 0, 0, 0.6); padding: 20px; border-radius: 25px;min-width:400px; font-size:24px; font-family: 宋体;">
                        <div class="tip">注：zindex大的影像会覆盖zindex小的影像</div>
                        <div class="tip">当影像的zindex值相等时，显示的是在最外层的那个影像</div>
                        <span>离线影像zindex: {{offlinezindex}}</span><div class="defultbtn" @click=offlineZindexAdd>+1</div>
                        <div class="defultbtn" @click=offlineZindexReduce>-1</div><br/>
                        <span>谷歌影像zindex: {{goolezindex}}</span><div class="defultbtn" @click= gooleZindexAdd>+1</div>
                        <div class="defultbtn" @click=gooleZindexReduce>-1</div>
                    </div>
                </div>
            `,
            data() {
                return {
                    _earth: undefined, // 注意：Earth和Cesium的相关变量放在vue中，必须使用下划线作为前缀！
                    offlinezindex: 0,
                    goolezindex: 0
                };
            },
            // 1.1 资源创建
            mounted() {
                // 1.1.1 创建地球
                var earth = new XE.Earth(this.$refs.earthContainer);

                // 1.1.2 场景配置
                earth.sceneTree.root = {
                    "expand": true,
                    "title": "影像",
                    "children": [{
                        "ref": 'offlineimage',
                        "czmObject": {
                            "xbsjType": "Imagery",
                            "name": "离线影像",
                            "show": true,
                            "xbsjImageryProvider": {
                                "createTileMapServiceImageryProvider": {
                                    "url": XE.HTML.cesiumDir + 'Assets/Textures/NaturalEarthII',
                                    "fileExtension": 'jpg',
                                },
                                "type": 'createTileMapServiceImageryProvider',
                            },
                        },
                    }, {
                        "ref": 'gooleimage',
                        "czmObject": {
                            "xbsjType": "Imagery",
                            "name": "谷歌影像",
                            "show": true,
                            "xbsjImageryProvider": {
                                "XbsjImageryProvider": {
                                    "url": "//www.google.cn/maps/vt?lyrs=s,h&gl=CN&x={x}&y={y}&z={z}",
                                    "srcCoordType": "GCJ02",
                                    "dstCoordType": "WGS84",
                                    "maximumLevel": 21,
                                },
                            }
                        },
                    }]
                };

                var offlineimage = earth.sceneTree.$refs.offlineimage.czmObject;
                var gooleimage = earth.sceneTree.$refs.gooleimage.czmObject;

                // 1.1.5 数据绑定
                this._offlinezindexUnbind = XE.MVVM.bind(this, 'offlinezindex', offlineimage, 'xbsjZIndex');
                this._gooleimageUnbind = XE.MVVM.bind(this, 'goolezindex', gooleimage, 'xbsjZIndex');


                this._earth = earth;

                // only for Debug
                window.offlineimage = offlineimage;
                window.gooleimage = gooleimage;
                window.earth = earth;
            },
            methods: {
                offlineZindexAdd() {
                    offlineimage.xbsjZIndex++;
                },
                offlineZindexReduce() {
                    offlineimage.xbsjZIndex--;
                },
                gooleZindexAdd() {
                    gooleimage.xbsjZIndex++;
                },
                gooleZindexReduce() {
                    gooleimage.xbsjZIndex--;
                }
            },
            // 1.2 资源销毁
            beforeDestroy() {
                // vue程序销毁时，需要清理相关资源
                this._offlinezindexUnbind = this._offlinezindexUnbind && this._offlinezindexUnbind();
                this._gooleimageUnbind = this._gooleimageUnbind && this._gooleimageUnbind();
                this._earth = this._earth && this._earth.destroy();
            },
        }

        // 2 创建vue程序
        // XE.ready()用来加载Cesium.js等相关资源
        XE.ready().then(() => {
            var app = new Vue({
                el: '#vueApp',
                components: {
                    EarthComp,
                },
            });
        });
    </script>
</body>

</html>